package com.aso114.project.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.aso114.project.R;
import com.aso114.project.base.BasesAdapter;
import com.aso114.project.bean.JingPinBean;
import com.aso114.project.commonview.MyListView;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class SelectedTopicAdapter extends BasesAdapter<SelectedTopicAdapter.ViewHolder> {

    ArrayList<JingPinBean> jingPinBean = new ArrayList<>();
    private Context context;
    private boolean isShow = true;

    public SelectedTopicAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(getInflater().inflate(R.layout.adapter_selected_topic, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        if ("1".equals(jingPinBean.get(position).getTypeId())) {
            holder.selectedTopicIcon.setImageResource(R.mipmap.jxtk_ji_ic);
        } else if ("2".equals(jingPinBean.get(position).getTypeId())) {
            holder.selectedTopicIcon.setImageResource(R.mipmap.jxtk_ya_ic);
        }
        if (jingPinBean.get(position).getIsLock() == 1) {//已付费
            if (isShow) {
                holder.selectedTopicTitleFf.setVisibility(View.VISIBLE);
            } else {
                holder.selectedTopicTitleFf.setVisibility(View.GONE);
            }
        } else {
            holder.selectedTopicTitleFf.setVisibility(View.GONE);
        }
        holder.selectedTopicTitle.setText(jingPinBean.get(position).getTitle());
        SelectedTopicItemAdapter adapter = new SelectedTopicItemAdapter(context, jingPinBean.get(position).getPaperList(), jingPinBean.get(position).getIsLock());
        holder.selectedTopicListView.setAdapter(adapter);
    }

    @Override
    public int getItemCount() {
        return jingPinBean.size();
    }

    public void setData(ArrayList<JingPinBean> jingPinBean) {
        this.jingPinBean = jingPinBean;
    }

    public void setIsShow(boolean isShow) {
        this.isShow = isShow;
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.selected_topic_icon)
        ImageView selectedTopicIcon;
        @BindView(R.id.selected_topic_title)
        TextView selectedTopicTitle;
        @BindView(R.id.selected_topic_title_ff)
        TextView selectedTopicTitleFf;
        @BindView(R.id.selected_topic_listView)
        MyListView selectedTopicListView;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
